home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Compression / Opener / Source / DirPanel.m < prev    next >
Text File  |  1993-07-15  |  3KB  |  98 lines

  1. /* DirPanel
  2.  *
  3.  * A category of SavePanel that extends SavePanel's capabilities
  4.  * to specifying directories instead of files.
  5.  *
  6.  * Copyright 1991, Scott Hess.  This source code may be redistributed
  7.  * and modified without restriction.
  8.  */
  9. #import "DirPanel.h"
  10.  
  11. @implementation SavePanel (DirPanel)
  12. /* This flags a real cancel.
  13.  */
  14. static BOOL notCancel=NO;
  15. /* This is where the real okButton is stored.
  16.  */
  17. static id realOkButton=nil;
  18. /* When we are masquerading as the okButton, catch setEnabled:.
  19.  */
  20. - setEnabled:(BOOL)flag
  21. {
  22.     [realOkButton setEnabled:YES];
  23.     return self;
  24. }
  25. /* All other methods are forwarded to Button.
  26.  * I'm assuming that the right Button methods make it through.  If
  27.  * it relies on responder chains and stuff, though, I'm probably
  28.  * sunk.  In any case, it does seem to work ...
  29.  */
  30. - forward:(SEL)aSelector :(marg_list)argFrame
  31. {
  32.     if( [realOkButton respondsTo:aSelector]) {
  33.         return [realOkButton performv:aSelector :argFrame];
  34.     }
  35.     return [self doesNotRecognize:aSelector];
  36. }
  37. /* Call this just like runModal.
  38.  */
  39. -(int)dirPanelRunModal
  40. {
  41.     int ret;
  42.       /* Store the okButton target/action. */
  43.     id okt=[okButton target];
  44.     SEL oka=[okButton action];
  45.       /* Enable the button, and redirect it at realOk:. */
  46.     [okButton setEnabled:YES];
  47.     [okButton setTarget:self];
  48.     [okButton setAction:@selector( realOk:)];
  49.         /*store away the okButton, and "become" it. */
  50.     realOkButton=okButton;
  51.     okButton=self;
  52.       /* Make sure we don't misfire on this. */
  53.     notCancel=NO;
  54.     /* OpenPanel doesn't seem to pay attention to setRequiredFileType,
  55.      * so I have to do things differently for it.  Actually, I
  56.      * would tend to recommend just using SavePanels, but that's
  57.      * just me.
  58.      *
  59.      * The idea, here, is that not many people are going to
  60.      * have files named *.abcdefghijklmnop, so the SavePanel
  61.      * can't find any, so it can only show directories, that
  62.      * you can move around in and look for stuff.  Since we're
  63.      * choosing directories, this is the right behaviour. */
  64.     if( [self isMemberOf:[SavePanel class]]) {
  65.     [self setRequiredFileType:"abcdefghijklmnop"];
  66.     ret=[self runModal];
  67.     } else {
  68.     const char *types[]={ "abcdefghijklmnop", NULL};
  69.         /* I cast to OpenPanel to remove the warning on compile. */
  70.     ret=[(OpenPanel *)self runModalForTypes:types];
  71.     }
  72.     /* If SavePanel thinks we canceled, check to see if _we_
  73.      * think so, too. */
  74.     if( !ret && notCancel) {
  75.     notCancel=NO;
  76.     ret=1;
  77.     }
  78.         /* Restore the okButton's target/action. */
  79.     okButton=realOkButton;
  80.     [okButton setTarget:okt];
  81.     [okButton setAction:oka];
  82.     return ret;
  83. }
  84. /* Handles ok's for the panel.  I need to pretend to be a cancel,
  85.  * for some reason.  Don't ask me - it wasn't working when I didn't
  86.  * do it, so I left it.
  87.  */
  88. - realOk:sender
  89. {
  90.     /* Mark this as a fake Cancel. */
  91.     notCancel=YES;
  92.       /* Use the ok: method to pull out any data from the form. */
  93.     [self ok:sender];
  94.       /* Use cancel: to get out of the modal loop. */
  95.     return [self cancel:sender];
  96. }
  97. @end
  98.